package com.leihao.product.controller;

import com.github.pagehelper.PageInfo;
import com.leihao.common.core.domain.R;
import com.leihao.product.domian.*;
import com.leihao.product.domian.listRequest.ListRequest;
import com.leihao.product.service.ProductAttrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productAttr")
@Api(tags = "商品类型管理")
public class ProductAttrController {

    @Autowired
    private ProductAttrService productAttrService;

    /**
     * 查询所有商品类型
     * @param listRequest
     * @return
     */
    @PostMapping("/findList")
    @ApiOperation(value = "查询所有一级商品类型")
    public R<PageInfo<ProductAttr>> findList(@Validated @RequestBody ListRequest listRequest)
    {
        PageInfo<ProductAttr> firstList = productAttrService.findList(listRequest);
        return R.ok(firstList);
    }
    /**
     * 根据编号查询商品类型信息
     * @param productAttrId
     * @return
     */
    @GetMapping("/findById/{productAttrId}")
    @ApiOperation(value = "根据编号查询商品类型信息")
    public R<ProductAttr> findById(@PathVariable Integer productAttrId)
    {
        ProductAttr productAttr = productAttrService.findById(productAttrId);
        return R.ok(productAttr);
    }
    /**
     * 逻辑删除
     * @param productAttrId
     * @return
     */
    @DeleteMapping("/delete/{productAttrId}")
    @ApiOperation(value = "逻辑删除")
    @ApiImplicitParam(name = "productAttrId",value = "主键ID",required = true,dataType = "Integer")
    public R delete(@PathVariable Integer productAttrId)
    {
        productAttrService.delete(productAttrId);
        return R.ok(null,"删除成功");
    }
    /**
     * 修改商品类型
     * @param productAttr
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改商品类型")
    public R update(@RequestBody ProductAttr productAttr)
    {
        productAttrService.update(productAttr);
        return R.ok(null,"修改成功");
    }
    /**
     * 添加商品类型
     * @param productAttr
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加商品类型")
    public R add(@Validated @RequestBody ProductAttr productAttr)
    {
        productAttrService.add(productAttr);
        return R.ok(null,"添加成功");
    }

    /**
     * 查询所有商品类型
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有商品类型")
    public R<List<ProductAttr>> findAll()
    {
        List<ProductAttr> list = productAttrService.findAll();
        return R.ok(list);
    }


}
